<script setup lang="ts">
import { ref } from 'vue'
import CollapsiblePanel from './common/CollapsiblePanel.vue'
import ToggleButton from './common/ToggleButton.vue'
import InputField from './common/InputField.vue'
import CopyToClipboard from './common/CopyToClipboard.vue'

// 定义props接口 - 保留landType属性以保持与其他组件一致的接口
// 虽然不区分单选和批次，但为了接口一致性仍需定义
interface Props {
  landType?: string
}

defineProps<Props>()

// 导入公共样式


// 表单数据状态定义
const illegalLandForm = ref({
  // 无合法来源建设用地情况
  变更调查年度: '',
  无合法来源建设用地面积: '',
  违法涉及农用地: '',
  违法涉及耕地: '',
  违法发生在2020年前: '否',
  违法涉及可调整地类: '',
  违法涉及未利用地: '',
  
  // 违法用地情形
  违法用地情形: '不涉及违法用地',
  临时用地情况: '无临时用地',
  
  // 临时用地相关数据
  批准临时用地面积: '',
  临时用地用途: '',
  临时用地批准起始年月: '',
  临时用地批准结束年月: '',
  实际临时用地面积: '',
  实际临时用途: '',
  
  // 违法用地相关数据
  违法用地总面积: '',
  违法新增面积: '',
  违法农用地: '',
  违法耕地: '',
  违法未利用地: '',
  处罚机关: '',
  处罚决定年月: '',
  处罚决定书文号: '',
  罚款标准: '',
  罚款金额: '',
  处罚执行到位年月: '',
  责任人姓名: '',
  处分类型: ''
})

// 生成要复制的文本
const generateCopyText = (): string => {
  let paragraph: string = ''
  
  // 构建无合法来源建设用地情况文本
  paragraph += `[存在无合法来源建设用地情况]\n`
  
  const hasIllegalLand = parseFloat(illegalLandForm.value.无合法来源建设用地面积 || '0') > 0
  if (hasIllegalLand) {
    paragraph += `${illegalLandForm.value.变更调查年度}年度国土变更调查现状成果中存在无合法来源建设用地。`
    paragraph += `该年度国土变更调查现状成果中建设用地${illegalLandForm.value.无合法来源建设用地面积}公顷因无合法来源，`
    paragraph += `相关建设用地按照违法用地发生前一年的国土（土地）利用现状地类报批，`
    paragraph += `涉及农用地${illegalLandForm.value.违法涉及农用地}公顷（其中耕地${illegalLandForm.value.违法涉及耕地}公顷`
    
    if (illegalLandForm.value.违法发生在2020年前 === '是') {
      paragraph += `；可调整地类${illegalLandForm.value.违法涉及可调整地类}公顷`
    }
    
    paragraph += `）、未利用地${illegalLandForm.value.违法涉及未利用地}公顷。（具体情况列表附后）\n\n`
  } else {
    paragraph += '\n'
  }
  
  // 构建违法用地情形文本
  paragraph += `〔是否涉及违法用地〕\n`
  
  if (illegalLandForm.value.违法用地情形 === "不涉及违法用地" && illegalLandForm.value.临时用地情况 === "无临时用地") {
    paragraph += `经我局核查，该批次用地未动工，不存在违法用地问题。`
  } else if (illegalLandForm.value.违法用地情形 === "不涉及违法用地" && illegalLandForm.value.临时用地情况 === "有临时用地") {
    paragraph += `经我局核查，该批次用地范围内存在经批准的临时用地。`
    paragraph += `批准临时用地面积${illegalLandForm.value.批准临时用地面积}公顷，`
    paragraph += `用途为${illegalLandForm.value.临时用地用途}，`
    paragraph += `批准时间为${illegalLandForm.value.临时用地批准起始年月}至${illegalLandForm.value.临时用地批准结束年月}；`
    paragraph += `实际用地面积${illegalLandForm.value.实际临时用地面积}公顷、`
    paragraph += `用途为${illegalLandForm.value.实际临时用途}，`
    paragraph += `目前在临时使用及土地复垦期限内，符合临时用地批准条件。`
  } else if (illegalLandForm.value.违法用地情形 === "违法用地") {
    paragraph += `经我局核查，该批次存在违法用地问题，`
    paragraph += `违法用地面积${illegalLandForm.value.违法用地总面积}公顷，`
    paragraph += `涉及新增建设用地面积${illegalLandForm.value.违法新增面积}公顷，`
    paragraph += `其中农用地${illegalLandForm.value.违法农用地}公顷（耕地${illegalLandForm.value.违法耕地}公顷）、`
    paragraph += `未利用地${illegalLandForm.value.违法未利用地}公顷。`
    paragraph += `${illegalLandForm.value.处罚机关}于${illegalLandForm.value.处罚决定年月}`
    paragraph += `对违法用地作出${illegalLandForm.value.处罚决定书文号}等的处罚决定`
    paragraph += `（罚款标准：${illegalLandForm.value.罚款标准}；罚款金额：${illegalLandForm.value.罚款金额}万元），`
    paragraph += `各项处罚已于${illegalLandForm.value.处罚执行到位年月}执行到位。`
    paragraph += `相关责任人员${illegalLandForm.value.责任人姓名}受到${illegalLandForm.value.处分类型}处分。`
  }
  
  return paragraph
}
</script>

<template>
  <div>
    <h1 class="text-3xl font-bold text-blue-700 text-center mb-6">违法用地单元</h1>
    
    <!-- 文件原文（可折叠） -->
    <CollapsiblePanel title="文件原文">
      <div class="mb-4">
        <h3 class="font-semibold text-gray-700 mb-2">一、业务指导处室</h3>
        <p class="text-gray-600">执法局</p>
      </div>
      
      <div class="mb-4">
        <h3 class="font-semibold text-gray-700 mb-2">二、审查标准</h3>
        <ol class="list-decimal pl-5 text-gray-600 space-y-2">
          <li>应当明确是否存在违法用地，如存在应已查处并落实到位。</li>
          <li>违法用地涉及生态保护红线、自然保护区的，应按规定处理。</li>
        </ol>
      </div>
    </CollapsiblePanel>
    
    <!-- 审查内容模板（常驻显示） -->
    <div class="border border-gray-200 rounded-lg shadow mb-6 bg-white text-left">
      <div class="bg-gray-50 p-4 border-b">
        <h2 class="text-xl font-semibold text-gray-800">三、审查内容模板</h2>
      </div>
      
      <div class="p-4">
        <!-- 区块1：无合法来源建设用地情况 -->
        <div class="section-block blue mb-6">
          <h3 class="text-lg font-semibold text-gray-800 mb-3">无合法来源建设用地情况</h3>
          <div class="text-gray-700 space-y-3">
            <p>[存在无合法来源建设用地情况]</p>
            
            <div class="space-y-4">
              <div class="flex flex-col md:flex-row md:items-center space-y-2 md:space-y-0">
                <label class="section-label blue md:w-1/4">变更调查年度：</label>
                <InputField v-model="illegalLandForm.变更调查年度" placeholder="年度" width="w-32" />
                <label class="section-label blue ml-0 md:ml-6">无合法来源建设用地面积：</label>
                <InputField v-model="illegalLandForm.无合法来源建设用地面积" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                <span class="text-sm ml-2">公顷</span>
              </div>
              
              <div v-if="parseFloat(illegalLandForm.无合法来源建设用地面积 || '0') > 0" class="text-blue-800 space-y-3">
                <div class="ml-4 pl-4">
                  <p>该年度国土变更调查现状成果中建设用地{{ illegalLandForm.无合法来源建设用地面积 }}公顷因无合法来源，相关建设用地按照违法用地发生前一年的国土（土地）利用现状地类报批，涉及：</p>
                  
                  <div class="flex flex-col md:flex-row md:items-center space-y-2 md:space-y-0 mt-2">
                    <label class="section-label blue md:w-1/4">农用地：</label>
                    <InputField v-model="illegalLandForm.违法涉及农用地" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷（其中耕地：</span>
                    <InputField v-model="illegalLandForm.违法涉及耕地" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷）</span>
                  </div>
                  
                  <div class="flex items-center mt-2 ml-4">
                    <ToggleButton 
                      v-model="illegalLandForm.违法发生在2020年前" 
                      :options="[
                        { label: '是', value: '是' },
                        { label: '否', value: '否' }
                      ]" 
                    />
                    <label class="section-label red ml-2">违法发生在2020年前：</label>
                  </div>
                  
                  <div v-if="illegalLandForm.违法发生在2020年前 === '是'" class="flex items-center mt-2 ml-4">
                    <span class="text-sm">可调整地类：</span>
                    <InputField v-model="illegalLandForm.违法涉及可调整地类" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                  
                  <div class="flex items-center mt-2 ml-4">
                    <span class="text-sm">未利用地：</span>
                    <InputField v-model="illegalLandForm.违法涉及未利用地" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                  
                  <p class="mt-2 ml-4"><span class="text-gray-700">（具体情况列表附后）</span></p>
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 区块2：违法用地情形 -->
        <div class="section-block green">
          <h3 class="text-lg font-semibold text-gray-800 mb-3">违法用地情形</h3>
          <div class="text-gray-700 space-y-3">
            <p>〔是否涉及违法用地〕</p>
            
            <!-- 用户选择判断区 -->
            <div class="space-y-4">
              <div class="flex items-center">
                <ToggleButton 
                  v-model="illegalLandForm.违法用地情形" 
                  :options="[
                    { label: '不涉及违法用地', value: '不涉及违法用地' },
                    { label: '违法用地', value: '违法用地' }
                  ]" 
                />
                <label class="section-label red ml-2">违法用地情形：</label>
              </div>
              
              <div v-if="illegalLandForm.违法用地情形 === '不涉及违法用地'" class="flex items-center">
                <ToggleButton 
                  v-model="illegalLandForm.临时用地情况" 
                  :options="[
                    { label: '无临时用地', value: '无临时用地' },
                    { label: '有临时用地', value: '有临时用地' }
                  ]" 
                />
                <label class="section-label red ml-2">临时用地情况：</label>
              </div>
            </div>

            <!-- 用户输入交互区 -->
            <div v-if="illegalLandForm.违法用地情形 === '不涉及违法用地' && illegalLandForm.临时用地情况 === '无临时用地'" class="text-blue-800 ml-4 pl-4">
              <p>经我局核查，该批次用地未动工，不存在违法用地问题。</p>
            </div>
            
            <div v-if="illegalLandForm.违法用地情形 === '不涉及违法用地' && illegalLandForm.临时用地情况 === '有临时用地'" class="text-blue-800 ml-4 pl-4 space-y-3">
              <p>经我局核查，该批次用地范围内存在经批准的临时用地。</p>
              
              <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div class="flex flex-col space-y-2">
                  <div class="flex items-center">
                    <label class="section-label blue w-40">批准临时用地面积：</label>
                    <InputField v-model="illegalLandForm.批准临时用地面积" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-40">临时用地用途：</label>
                    <InputField v-model="illegalLandForm.临时用地用途" placeholder="用途" width="w-48" />
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-40">批准起始年月：</label>
                    <InputField v-model="illegalLandForm.临时用地批准起始年月" placeholder="*年*月" width="w-32" />
                    <span class="text-sm mx-2">至</span>
                    <InputField v-model="illegalLandForm.临时用地批准结束年月" placeholder="*年*月" width="w-32" />
                  </div>
                </div>
                
                <div class="flex flex-col space-y-2">
                  <div class="flex items-center">
                    <label class="section-label blue w-40">实际临时用地面积：</label>
                    <InputField v-model="illegalLandForm.实际临时用地面积" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-40">实际临时用途：</label>
                    <InputField v-model="illegalLandForm.实际临时用途" placeholder="用途" width="w-48" />
                  </div>
                </div>
              </div>
              
              <p>目前在临时使用及土地复垦期限内，符合临时用地批准条件。</p>
            </div>
            
            <div v-if="illegalLandForm.违法用地情形 === '违法用地'" class="text-blue-800 ml-4 pl-4 space-y-3">
              <p>经我局核查，该批次存在违法用地问题，具体情况如下：</p>
              
              <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div class="flex flex-col space-y-2">
                  <div class="flex items-center">
                    <label class="section-label blue w-48">违法用地总面积：</label>
                    <InputField v-model="illegalLandForm.违法用地总面积" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">涉及新增建设用地面积：</label>
                    <InputField v-model="illegalLandForm.违法新增面积" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">其中农用地：</label>
                    <InputField v-model="illegalLandForm.违法农用地" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷（耕地：</span>
                    <InputField v-model="illegalLandForm.违法耕地" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷）</span>
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">未利用地：</label>
                    <InputField v-model="illegalLandForm.违法未利用地" type="number" step="0.01" min="0" placeholder="面积" width="w-32" />
                    <span class="text-sm ml-2">公顷</span>
                  </div>
                </div>
                
                <div class="flex flex-col space-y-2">
                  <div class="flex items-center">
                    <label class="section-label blue w-48">处罚机关：</label>
                    <InputField v-model="illegalLandForm.处罚机关" placeholder="处罚机关" width="w-64" />
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">处罚决定年月：</label>
                    <InputField v-model="illegalLandForm.处罚决定年月" placeholder="*年*月" width="w-40" />
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">处罚决定书文号：</label>
                    <InputField v-model="illegalLandForm.处罚决定书文号" placeholder="文号" width="w-64" />
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">罚款标准：</label>
                    <InputField v-model="illegalLandForm.罚款标准" placeholder="罚款标准" width="w-64" />
                  </div>
                  <div class="flex items-center">
                    <label class="section-label blue w-48">罚款金额：</label>
                    <InputField v-model="illegalLandForm.罚款金额" type="number" step="0.01" min="0" placeholder="金额" width="w-32" />
                    <span class="text-sm ml-2">万元</span>
                  </div>
                </div>
              </div>
              
              <div class="mt-2">
                <div class="flex items-center">
                  <label class="section-label blue w-48">处罚执行到位年月：</label>
                  <InputField v-model="illegalLandForm.处罚执行到位年月" placeholder="*年*月" width="w-40" />
                </div>
                <div class="flex items-center mt-2">
                  <label class="section-label blue w-48">责任人姓名：</label>
                  <InputField v-model="illegalLandForm.责任人姓名" placeholder="姓名" width="w-40" />
                  <label class="section-label blue ml-6">处分类型：</label>
                  <InputField v-model="illegalLandForm.处分类型" placeholder="处分类型" width="w-64" />
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 复制按钮和显示复制的文本内容 -->
    <CopyToClipboard :text="generateCopyText()" />
  </div>
</template>

<style scoped>
/* 组件特定样式保留 */
</style>